package com.ysl.fairy_could_class.controller;

import com.ysl.fairy_could_class.domain.User;
import com.ysl.fairy_could_class.service.UserService;
import com.ysl.fairy_could_class.util.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/user")
@Api(tags = "用户管理")
public class UserController {
    @Autowired
    UserService service;
    @GetMapping("/getUserListAll")
    @ApiOperation(value = "获取用户列表")
    public AjaxResult getUserListAll() {
        System.out.println(service.selectAll());
        return AjaxResult.success(service.selectAll());
    };
    @GetMapping("/getUserById")
    @ApiOperation(value = "根据id查询用户信息")
    public AjaxResult getUserById(int id) {
        System.out.println(service.selectById(id));
        return AjaxResult.success(service.selectById(id));
    }
    @PostMapping("/addUser")
    @ApiOperation(value = "新增用户")
    public AjaxResult addUser(@RequestBody User user) {
        return AjaxResult.success(service.SaveUser(user));
    }
    @PostMapping("/UpdateUser")
    @ApiOperation(value = "修改用户密码")
    public AjaxResult UpdateUser(@RequestBody User user){
        return AjaxResult.success(service.UpdateUser(user));
    }
    @PostMapping("/DeleteUser")
    @ApiOperation(value = "删除用户")
    public AjaxResult DeleteUser(int id) {
        return AjaxResult.success(service.DeleteUser(id));
    }
    @PostMapping("/UserLogin")
    @ApiOperation(value = "用户登录")
    public AjaxResult UserLogin(User user) {
        return AjaxResult.success(service.checkUser(user));
    }
}


